import numpy as np
import cv2
import sys
import matplotlib.pyplot as plt
from moviepy.editor import VideoFileClip
from IPython.display import HTML
%matplotlib inline
%load_ext autoreload
#using autoreload 1 to reload all modules imported by %aimport everytime before executing the python code typed .
%autoreload 2
%aimport lane_detection
img = cv2.imread('./test_images/test5.jpg')
img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
gray = cv2.cvtColor(img, cv2.COLOR_RGB2GRAY)
sobel_img = lane_detection.abs_sobel_thresh(gray, thresh=(10, 200))
lane_detection.plt_images(img, 'Source image', sobel_img, 'Sobel image')
dir_binary = lane_detection.dir_threshold(gray, thresh=(np.pi/6, np.pi/2))
lane_detection.plt_images(img, 'Source image', dir_binary, 'dir Sobel image')
combined = ((sobel_img == 1) & (dir_binary == 1))
lane_detection.plt_images(sobel_img, 'sobel image', combined, 'combined Sobel image')
thresholded = lane_detection.combine_thresh(img,s_thresh=(100, 255), l_thresh=(120, 255))
lane_detection.plt_images(img, 'Source image', thresholded, 'combined threshold image')
thresholded_img, warped_img, Minv = lane_detection.warp_image_to_birdseye_view_gray(img)
lane_detection.plt_images(img, 'Source image', warped_img, 'warped image')
left_fit, right_fit,out_img, lefty, leftx, righty, rightx, ploty = lane_detection.fitlines(warped_img, nwindows=15, margin=100, minpix = 50 )
plt.imshow(out_img)
<matplotlib.image.AxesImage at 0x20b8da453d0>
center,left_curverad, right_curverad = lane_detection.lane_curvatures(img, lefty, leftx, righty, rightx, ploty)
print(center)
print(left_curverad)
print(right_curverad)
0.29517596785131006 1570.288041098253 5567.9997606255565
result,color_warp = lane_detection.draw_lane(img, warped_img, left_fit, right_fit, ploty, center, left_curverad, right_curverad, Minv)
lane_detection.plt_images(result, 'Output image', color_warp, 'Lane image')
processed_img = lane_detection.software_pipeline_v1(img)
plt.figure(figsize=(10,5))
plt.imshow(processed_img)
<matplotlib.image.AxesImage at 0x20b8d979d90>
processed_img = lane_detection.software_pipeline_v2(img)
plt.figure(figsize=(10,5))
plt.imshow(processed_img)
<matplotlib.image.AxesImage at 0x20b8ba601c0>
lane_detection.createVideo("./test_videos/challenge_video.mp4","challenge_video_output.mp4")
lane_detection.createVideo("./test_videos/challenge_video.mp4","challenge_video_output_debug_mode.mp4", "1")
lane_detection.createVideo("./test_videos/project_video.mp4","project_video_output.mp4", "0")
lane_detection.createVideo("./test_videos/project_video.mp4","project_video_output_debug_mode.mp4", "1")